package com.twl.app.base.util;

import org.hibernate.Query;
import org.hibernate.Session;

import com.twl.app.base.entity.SalParam;
import com.twl.common.constant.SalConstant;
import com.twl.core.framework.dao.WSHibernateDaoSupportProxy;

/**
 * 系统参数工具类
 * 
 * @author Val
 * 
 */
public class SalParamUtils {

	public static String getValueByTypeAndKey(String type, String key) {
		// WSHibernateDaoSupportProxy wSHibernateDaoSupportProxy =
		// (WSHibernateDaoSupportProxy)
		// BeanFactoryHolder.getBean("wSHibernateDaoSupportProxy");
		// SalParam salParam = null;
		// try {
		// salParam = (SalParam)
		// wSHibernateDaoSupportProxy.uniqueResult(" from SalParam where isDelete ='"+SalConstant.NOT_DELETE+"' and paramType ='"
		// + type + "' and paramKey ='" + key + "' ");
		// } catch (Exception e) {
		// e.printStackTrace();
		// }
		String hql = " from SalParam where isDelete ='" + SalConstant.NOT_DELETE + "' and paramType ='" + type + "' and paramKey ='" + key + "' ";

		WSHibernateDaoSupportProxy wSHibernateDaoSupportProxy = (WSHibernateDaoSupportProxy) BeanFactoryHolder.getBean("wSHibernateDaoSupportProxy");
		SalParam salParam = null;
		Session session = null;
		try {
			session = wSHibernateDaoSupportProxy.getSessionFactory().openSession();

			Query query = session.createQuery(hql);
			salParam = (SalParam) query.uniqueResult();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (session != null && session.isConnected()) {
				session.close();
			}
		}

		return salParam.getParamValue();
	}
}
